package com.notepad.ui;



import com.notepad.R;
import com.notepad.util.Constant;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;


public class WelcomeActivity extends Activity {
	private RelativeLayout mWelcomeRelativeLayout;
	
	private SharedPreferences mSharePreference;
	private Editor editor;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start);
		init();
		setAnimation();
	}

	private void init() {
		mWelcomeRelativeLayout = (RelativeLayout) findViewById(R.id.start_layout);
		
	}
	private void setAnimation() {
		Animation anim = AnimationUtils.loadAnimation(getApplication(), R.anim.welcome_anim);
		mWelcomeRelativeLayout.setAnimation(anim);
		anim.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				redirectTo();
			}
		});
		
		
	}

	
	private void redirectTo(){
		mSharePreference = getSharedPreferences(Constant.First_peference, Context.MODE_PRIVATE);
		if(mSharePreference.getBoolean("isFirstIn", true)){
			editor = mSharePreference.edit();
			editor.putBoolean("isFirstIn", false);
			editor.commit();
			Intent intent = new Intent();
			intent.setClass(this, SplashPager.class);
			startActivity(intent);
			finish();
		}else{
			Intent intent = new Intent(this,MainActivity.class);
			startActivity(intent);
			finish();
		}
	}
	
}
